package com.gxa.controller.discrepancy;
import java.util.Date;

import com.gxa.common.utils.R;
import com.gxa.entity.discrepancy.Passage;
import com.gxa.entity.discrepancy.search.PassageSearchMap;
import com.gxa.service.discrepancy.PassageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

import static com.gxa.common.utils.R.error;
import static com.gxa.common.utils.R.ok;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:43:53
 */
@Api(tags = "记录管理--->人员通行记录")
@RestController
@RequestMapping("/passage")
public class PassageController {

    @Autowired
    private PassageService service;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("人员通行记录列表接口")
    @GetMapping("/list")
    public R queryAll(PassageSearchMap map){

        return ok("successs").put("data",service.queryByPage(map));
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("新增人员通行记录接口")
    @PostMapping("/add")
    public R add(@RequestBody Passage device){
        boolean save = service.save(device);
        if(save){
            return ok("添加成功！");
        }
        return error("add fail");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("删除人员通行记录接口")
    @DeleteMapping("/del/{id}")
    public R del(@PathVariable("id") Integer id){
        if(service.removeById(id)){
            return ok("删除成功！");
        }

        return error("del error");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("编辑人员通行记录接口")
    @PutMapping("/edit")
    public R edit(@RequestBody Passage device){
        if(service.updateById(device)){
            return ok("更新成功！");
        }
        return error("edit error");
    }
    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("通行位置 接口")
    @GetMapping("/locations")
    public R locations(){
        return ok().put("data",service.getPassLocations());
    }
}
